/*
*初始化 流水号码表
 */
package main

import (
	// "net/http"
	// "encoding/json"
	// "strconv"
	// "time"
	// "github.com/dgrijalva/jwt-go"
	// "github.com/labstack/echo"

	"time"

	"gopkg.in/mgo.v2/bson"
	// "github.com/jinzhu/gorm"
	"oxy_server/model"
	"oxy_server/module/log"
)

type (
	operationplan struct {
		ID           bson.ObjectId `json:"_id" bson:"_id"`
		BatchNumber  string        `json:"batchnumber" bson:"batchnumber"`   //批次号
		StyleNumber  string        `json:"stylenumber" bson:"stylenumber"`   //款数
		CategoryId   string        `json:"categoryid" bson:"categoryid"`     //品类
		ProductKind  string        `json:"productkind" bson:"productkind"`   //品类
		TargetNumber string        `json:"targetnumber" bson:"targetnumber"` //目标数量
		TargetCost   string        `json:"targetcost" bson:"targetcost"`     //目标成本
		Value        string        `json:"value" bson:"value"`               //货值
		TargetPrice  string        `json:"targetprice" bson:"targetprice"`   //目标售价
		PremiumRate  string        `json:"premiumrate" bson:"premiumrate"`   //加价倍率
		Brand        string        `json:"brand" bson:"brand"`               //品牌
		BrandId      string        `json:"brandid" bson:"brandid"`           //品牌
		CreateTime   int64         `json:"createtime" bson:"createtime"`     //品牌
	}
)

func main() {
	model.DB().Dbname = "OxyCms"
	model.DB().Document = "operation_plan"
	query, _, err := model.DB().Query(nil, 0, 0)
	if err != nil {
		log.Error("查询出错 品牌列表", err)
		return
	}
	timeTemplate1 := "2006-01-02 15:04:05" //常规类型
	ps := []operationplan{}
	query.All(&ps)
	for _, item := range ps {
		t1 := item.BatchNumber[0:4] + "-" + item.BatchNumber[4:6] + "-" + item.BatchNumber[6:8] + " 15:04:05"
		stamp, _ := time.ParseInLocation(timeTemplate1, t1, time.Local)
		item.CreateTime = stamp.Unix()
		log.Info("t1", t1)
		log.Info("stamp.Unix()", stamp.Unix())
		model.DB().Update(bson.M{"_id": item.ID}, bson.M{"$set": bson.M{"createtime": stamp.Unix() * 1000}})
	}

	log.Info("success")
}
